/*
* @Author: Josh
* @Date:   2019-01-23 17:52:15
* @Last Modified by:   josh
* @Last Modified time: 2019-01-28 21:48:32
*/
'use strict'

var _mall = require('util/mall.js');

var _user = {
    //用户登录
    login : function(userInfo, resolve, reject){
        _mall.request({
            url     : _mall.getServerUrl('/user/login.do'),
            data    : userInfo,
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    //检查登录状态
    checkLogin : function(resolve, reject){
        _mall.request({
            url     : _mall.getServerUrl('/user/get_user_info.do'),
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    //用户名验证
    checkUsername : function(username, resolve, reject){
        _mall.request({
            url     : _mall.getServerUrl('/user/check_valid.do'),
            data    : {
                type    : 'username',
                str     : username 
            },
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    //用户注册
    register : function(userInfo, resolve, reject){
        _mall.request({
            url     : _mall.getServerUrl('/user/register.do'),
            data    : userInfo,
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    //取得找回密码问题
    getQuestion : function(username, resolve, reject){
        _mall.request({
            url     : _mall.getServerUrl('/user/forget_get_question.do'),
            data    : {
                    username : username
            },
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    //检查密码找回答案是否输入正确
    checkAnswer : function(userInfo, resolve, reject){
        _mall.request({
            url     : _mall.getServerUrl('/user/forget_check_answer.do'),
            data    : userInfo,
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    //重置密码
    resetPaword : function(userInfo, resolve, reject){
        _mall.request({
            url     : _mall.getServerUrl('/user/forget_reset_password.do'),
            data    : userInfo,
            method  : 'POST',
            success : resolve,
            error   : reject
        }); 
    },
    //获取用户信息
    getUserInfo : function(resolve, reject){
        _mall.request({
            url     : _mall.getServerUrl('/user/get_information.do'),
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    //更新个人信息
    updateUserInfo : function(userInfo, resolve, reject){
        _mall.request({
            url     : _mall.getServerUrl('/user/update_information.do'),
            data    : userInfo,
            method  : 'POST',
            success : resolve,
            error   : reject
        }); 
    },
    //登录状态下更新密码
    updatePassword : function(userInfo, resolve, reject){
        _mall.request({
            url     : _mall.getServerUrl('/user/reset_password.do'),
            data    : userInfo,
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    //登出
    logout : function(resolve, reject){
        _mall.request({
            url     : _mall.getServerUrl('/user/logout.do'),
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    }
}

module.exports = _user;